/*
 * @Author: _oufen
 * @Date: 2023-04-15 09:06:56
 * @LastEditTime: 2023-07-04 08:23:37
 * @Description: TIM4定时函数
 */

/* Includes -------------------------------------------------------------------------------------------------------------*/

#include "timer6.h"
// #include "myconfig.h"

/* Define -----------------------------------------------------------------------------------------------------------------*/

/* Functions -----------------------------------------------------------------------------------------------------------------*/
/**
 * @brief 	TIM4初始化 用作定时器10ms
 * @param 	无
 * @retval  无
 */
void Timer6_Init(uint16_t psc, uint16_t arr)
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    // TIM_OCInitTypeDef  TIM_OCInitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

    //	MY_GPIO_Init(GPIOB,GPIO_Pin_6,GPIO_Mode_AF_PP);
    //	MY_GPIO_Init(GPIOB,GPIO_Pin_7,GPIO_Mode_AF_PP);
    //	MY_GPIO_Init(GPIOB,GPIO_Pin_8,GPIO_Mode_AF_PP);
    //	MY_GPIO_Init(GPIOB,GPIO_Pin_9,GPIO_Mode_AF_PP);

    TIM_TimeBaseStructure.TIM_Period = arr;
    TIM_TimeBaseStructure.TIM_Prescaler = psc;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

    NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // 下面三部分和TIM_ARRPreloadConfig(TIM1,ENABLE)，TIM_CtrlPWMOutputs(TIM1,ENABLE); 使用PWM时打开
    //	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //选择定时器模式:TIM脉冲宽度调制模式2
    //	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
    //	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出极性:TIM输出比较极性低

    //	TIM_OC1Init(TIM4, &TIM_OCInitStructure);  //根据T指定的参数初始化外设TIM1 4OC1
    //	TIM_OC2Init(TIM4, &TIM_OCInitStructure);  //根据T指定的参数初始化外设TIM1 4OC1
    //	TIM_OC3Init(TIM4, &TIM_OCInitStructure);  //根据T指定的参数初始化外设TIM1 4OC1
    //	TIM_OC4Init(TIM4, &TIM_OCInitStructure);  //根据T指定的参数初始化外设TIM1 4OC1

    //	TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);  //使能TIM14在CCR1上的预装载寄存器
    //	TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);  //使能TIM14在CCR1上的预装载寄存器
    //	TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);  //使能TIM14在CCR1上的预装载寄存器
    //	TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);  //使能TIM14在CCR1上的预装载寄存器
    //
    //	TIM_ARRPreloadConfig(TIM4,ENABLE);//ARPE使能

    TIM_ClearFlag(TIM6, TIM_FLAG_Update);
    TIM_ClearITPendingBit(TIM6, TIM_IT_Update); // 清除更新中断请求位        //这句话一定要放在使能更新中断前面，否则定时器初始化会直接进入一次更新中断
    TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);

    TIM_Cmd(TIM6, ENABLE);
}

/*void TIM6_IRQHandler(void) // 10ms
{
    if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET)
    {
        AutoReloadCallback(); // 定时调用
        TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
        LED1 = !LED1;
    }
}*/

/*****************************************************END OF FILE*********************************************************/
